package com.haier.uos.weather.city.uitl;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.*;

public class XmlBuilder {
    private XmlBuilder(){}

    public static Object xmlStrToObject(Class<?> clazz, String xmlStr) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(clazz);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        Reader reader = new StringReader(xmlStr);
        Object xmlObject = unmarshaller.unmarshal(reader);
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return xmlObject;
    }
}
